home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_12 / colvin / runtime.h < prev   
C/C++ Source or Header  |  1995-10-10  |  2KB  |  70 lines

  1. ////////////////////////////////////////////////////////////
  2. // runtime.h
  3. //
  4. // Runtime library with patches to track working papers.
  5.  
  6. #ifndef RUNTIME_H
  7. #define RUNTIME_H
  8.  
  9. #include <assert.h>
  10. #include <errno.h>
  11. #include <limits.h>
  12. #include <malloc.h>
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <time.h>
  18.  
  19. #include <iostreams.h>
  20.  
  21. // Boolean type.
  22. typedef int bool;
  23.  
  24. // Exceptions.
  25. struct exception { virtual ~exception(){} };
  26. struct bad_alloc : exception {};
  27.  
  28. // Low level memory allocation functions.
  29. void* allocate(size_t) throw();
  30. void deallocate(void*) throw();
  31.  
  32. // Installable new handler.
  33. typedef void (*new_handler)();
  34. new_handler set_new_handler(new_handler) throw();
  35.  
  36. // Standard memory allocation operators.
  37. void* operator new(size_t) throw(bad_alloc);
  38. void* operator new[](size_t) throw(bad_alloc);
  39. void operator delete(void*);
  40. void operator delete[](void*);
  41.  
  42. // Default allocator.
  43. template<class T> struct allocator {
  44.    void* allocate(size_t size) throw(bad_alloc) {
  45.       return ::operator new(n);
  46.    }
  47.    void deallocate(T* p) throw() { :: operator delete(p); }
  48. };
  49.  
  50. // Allocate via an allocator.
  51. template<class Allocator> inline void*
  52. operator new(size_t n,Allocator& r) throw(bad_alloc) {
  53.    return r.allocate(n);
  54. };
  55. template<class Allocator> inline void* 
  56. operator new[](size_t n,Allocator& r) throw(bad_alloc) {
  57.    return r.allocate(n);
  58. };
  59.  
  60. // Allocate in place.
  61. inline void* operator new(size_t n,void* p) throw() { 
  62.    return p; 
  63. }
  64. inline void* operator new[](size_t n,void* p) throw() { 
  65.    return p; 
  66. }
  67.  
  68. #endif
  69.  
  70.